from flask import Flask, request, jsonify

from read import read

app = Flask(__name__)


@app.route("/ocr", methods=["POST"])
def perform_ocr():
    try:
        # 从请求中获取图像路径
        data = request.get_json()
        image_path = data.get("image_path")
        return read(image_path)
    except Exception as e:
        print(e)
        return jsonify({"error": str(e)}), 500


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000, debug=False)
